<?php
class WJ_View_Helper_Blocks extends Zend_View_Helper_Abstract {


	public function blocks($container) {
		$blocks = '';
		$cache = Zend_Registry::get('Zend_Cache');
	
		$core_blocks = new Engine_Db_Table_CoreBlocks();
		$select = $core_blocks->select();
		$select->where("block_type_id = '$container'");
		$select->order('block_order');
		$results = $core_blocks->fetchAll($select);
		foreach ($results as $row) { 
			$blocks = $blocks . $this->createBlock($row);
		}
		
		return $blocks;
	}
	
	protected  function createBlock($row) {	
		
		$widget_id = $row['block_widget_id'];
		$core_widgets = new Engine_Db_Table_CoreWidgets();
		$select = $core_widgets->select();
		$select->where("widget_id = $widget_id");
		$results = $core_widgets->fetchRow($select);
		
		$widget = new $results['widget_classname'](unserialize($row['block_widget_config']));		
		return $widget->run();
		
	}
	
	protected  function createBlock2($container, $datarow) {

		$title = '';
		if (strlen($datarow['block_title'])>0) {
			$title = sprintf('
	                                            <div class="art-blockheader">
	                                                 <div class="t">%s</div>
	                                            </div>', $datarow['block_title']
	        );
		}
			
		$content = $datarow['block_content'];		
		$block = sprintf('
                            <div class="art-block">
                                <div class="art-block-body">
											%s
                                            <div class="art-blockcontent">
                                                <div class="art-blockcontent-body">
                                            		<!-- block-content -->
													%s
                                            		<!-- /block-content -->
                                            
                                            		<div class="cleared"></div>
                                                </div>
                                            </div>
                            		<div class="cleared"></div>
                                </div>
                            </div>', $title, $content
		);
     	return $block;                       
	}

}

?>